package com.mixide.ui.part.memory;

import javax.inject.Inject;

import org.eclipse.e4.core.di.annotations.Creatable;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

import com.mixide.ui.service.IconCache;

import lombok.RequiredArgsConstructor;

@Creatable @RequiredArgsConstructor(onConstructor_=@Inject)
public class MemoryLabelProvider extends LabelProvider implements ITableLabelProvider {

	private final IconCache iconCache;
	
	public String getColumnText(Object element, int columnIndex) {
		if (!(element instanceof WordRow)) {
			return "";
		}
		WordRow row = (WordRow) element;
		switch (columnIndex) {
		case 0: // no
			return row.getNo();
		case 1: // sign
			return row.getSign();
		case 2: // byte1
			return row.getByte1();
		case 3: // byte2
			return row.getByte2();
		case 4: // byte3
			return row.getByte3();
		case 5: // byte4
			return row.getByte4();
		case 6: // byte5
			return row.getByte5();
		case 7: // operation
			return row.getOperation();
		case 8: // toChar
			return "\"" + row.getToChar() + "\"";
		case 9: // toInt
			return row.getToInt();
		default:
			return "";
		}
	}

	public Image getColumnImage(Object element, int columnIndex) {
		if (element instanceof WordRow && columnIndex == 0) {
			if (((WordRow) element).getSign().equals("+")) {
				return this.iconCache.stockImages[this.iconCache.iconPositive];
			}
			return this.iconCache.stockImages[this.iconCache.iconNegative];
		}
		return null;
	}
}
